package thread;

public class YieldDemo implements Runnable{
	//yield是让当钱线程暂停一下，进入就绪队列的最后面，如果没有队列，就无效，重新调度一次。但是可能下次还是调度这个线程。
	public void run() {
		for(int i = 1;i<8;i++){
			System.out.println(Thread.currentThread().getName()+"运行了"+i+"次");
			if(i==5){
				//上面不如下面
				//Thread.currentThread().yield();
				Thread.yield();
			}
		}
	}
	public static void main(String[] args) {
		YieldDemo yd = new YieldDemo();
		Thread t1 = new Thread(yd,"max");
		Thread t2 = new Thread(yd,"normal");
		Thread t3 = new Thread(yd,"min");
		/*t1.setPriority(Thread.MAX_PRIORITY);
		t2.setPriority(Thread.NORM_PRIORITY);
		t3.setPriority(Thread.MIN_PRIORITY);*/
		t3.start();
		t2.start();
		t1.start();
	}

}
